package com.example.langchain4j.controller;

import com.example.langchain4j.common.Result;
import com.example.langchain4j.service.ChaiLiangProcessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 裁量权基准查询控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/chailiang")
@Tag(name = "裁量权基准", description = "裁量权基准查询相关接口")
public class ChaiLiangController {

    @Resource
    private ChaiLiangProcessService chaiLiangProcessService;

    /**
     * 查询裁量权基准建议
     *
     * @param approvalFile 立案审批表文件（Word或PDF）
     * @param interrogationFile 询问笔录文件（Word或PDF）
     * @return 裁量权基准建议
     */
    @PostMapping("/query")
    @Operation(summary = "查询裁量权基准", description = "根据立案审批表和询问笔录，调用AI模型提取关键信息，查询裁量权基准建议")
    public Result<Map<String, Object>> queryChaiLiang(
            @Parameter(description = "立案审批表文件", required = true)
            @RequestParam("approvalFile") MultipartFile approvalFile,

            @Parameter(description = "询问笔录文件", required = true)
            @RequestParam("interrogationFile") MultipartFile interrogationFile) {

        try {
            log.info("收到裁量权基准查询请求，立案审批表: {}, 询问笔录: {}",
                    approvalFile.getOriginalFilename(),
                    interrogationFile.getOriginalFilename());

            Map<String, Object> result = chaiLiangProcessService.processChaiLiangQuery(
                    approvalFile, interrogationFile);

            return Result.success(result);

        } catch (Exception e) {
            log.error("裁量权基准查询失败", e);
            return Result.error(500, "裁量权基准查询失败: " + e.getMessage());
        }
    }
}